using System;
using System.Configuration.Abstractions;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.Companies;
using Sustainalytics.Entities;

namespace Sustainalytics.Portfolios.BL
{
    public class SecurityFactory: IPortfolioDetailsFactory
    {
        ICompanyMatchingLogic _companyMatchingLogic;

        protected SecurityFactory(ICompanyMatchingLogic companyMatchingLogic)
        {
            _companyMatchingLogic = companyMatchingLogic;
        }
        public static IPortfolioDetailsFactory GetFactory(ICompanyMatchingLogic companyMatchingLogic)
        {
            return new SecurityFactory(companyMatchingLogic);
        }
        public PortfolioDetails CompanySearchToPortfolioDetails(Guid securityInternalId, Company company)
        {
            var newDetail = new PortfolioDetails
            {
                CompanyId = _companyMatchingLogic.FindGuidForOneCompany(company),
                Id = securityInternalId,
                CompanyNameLowercase = company.CompanyName.ToLowerInvariant(),
                CompanyNameUrlFriendly = _companyMatchingLogic.FindCompanyNameFriendlyURLForId(company.CompanyId),
                SecurityId = _companyMatchingLogic.FindSecurityIdForCompanyId(company.CompanyId),
                DisplayInfo = new DisplayInformation(String.Empty, company.CompanyId.ToString()),
                MatchedInfo = new MatchedInformation(company.CompanyId.ToString(), company.CompanyName)
            };
            return newDetail;
        }
    }
}